import 'package:flutter/material.dart';
import 'package:tiktokadult/config/config.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/image/custom_network_image.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

import '../../../hj_model/home/home_tabs_entity.dart';
import '../../../hj_model/splash/domain_source_model.dart';

class HomeJgAreaWidget extends StatelessWidget {
  final ModuleData? tabModel;
  HomeJgAreaWidget(this.tabModel);

  @override
  Widget build(BuildContext context) {
    List<JGAreaModel> dataArr = (Config.jgArea ?? []).where((element) => element.mid == tabModel?.id).toList();
    if (dataArr.isEmpty) {
      return Container();
    } else {
      return Container(
        height: 62,
        margin: EdgeInsets.fromLTRB(12, 0, 0, 12),
        child: LayoutBuilder(
          builder: (BuildContext context, BoxConstraints constraints) {
            final width = (constraints.maxWidth - 5 * 16) / 5.5;
            final height = width * 48 / 58;
            return SizedBox(
              height: height,
              child: ListView.builder(
                itemCount: dataArr.length,
                padding: EdgeInsets.zero,
                scrollDirection: Axis.horizontal,
                itemBuilder: (context, index) {
                  JGAreaModel model = dataArr[index];
                  return Container(
                    height: 62,
                    width: width,
                    margin: EdgeInsets.only(right: 16),
                    child: InkWell(
                      onTap: () {
                        pushToPageByLink(model.linkUrl, id: model.id);
                      },
                      child: Column(
                        children: [
                          Expanded(
                            child: Container(
                              alignment: Alignment.center,
                              child: AspectRatio(
                                aspectRatio: 1,
                                child: NetworkImageLoader(imageUrl: model.img ?? ""),
                              ),
                            ),
                          ),
                          3.sizeBoxH,
                          Text(
                            model.name ?? "",
                            maxLines: 1,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 11,
                            ),
                          ),
                        ],
                      ),
                    ),
                  );
                },
              ),
            );
          },
        ),
      );
    }
  }
}
